/*! \file BaseIrDecoder.h Holds the base class for the IR decodes ported from the old MceIr Driver. */
#ifndef __BASE_IR_DECODER_INCLUDED__
#define __BASE_IR_DECODER_INCLUDED__

#include "IIrDecoder.h"
#include "Publisher.h"
#include "ILogger.h"
#include "MceTypes.h"

/*! The base class for the ported IR decodes, contains the shared elements from the subclasses. */
class BaseIrDecoder : public IIrDecoder
{
protected:
	enum DETECTION_STATE
	{
		DETECT_HEADER_PULSE,
		DETECT_HEADER_SPACE,
		DETECT_PRE_DATA,
		DETECT_DATA,
		DETECT_KEYCODE,
		DETECT_LEADING
	};

    DETECTION_STATE		m_DetectState;
    unsigned char		m_Bit;
    unsigned char		m_HalfBit;
    unsigned long		m_Header;
    unsigned long		m_Code;
    unsigned long		m_LastCode;
    unsigned long		m_LastTime;
    unsigned long		m_RepeatCount;
    bool				m_LongPulse;
    bool				m_LongSpace;
	unsigned long		m_KbdFirstRepeat;
	unsigned long		m_KbdNextRepeats;

	PublisherPtr m_Publisher;
	ILoggerPtr m_Logger;
public:
	BaseIrDecoder( ILoggerPtr logger, PublisherPtr publisher );
	virtual bool process ( unsigned long * data, size_t count ) = 0;
	void reset();
};

#endif